<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

/*
 * Geoffrey START Added Authentication Code
 */
include 'routes/login.php';

// Views Product Voucher
Route::get('po/viewVoucher/{id}', [ 'uses' => 'PurchaseOrderController@generateVoucher' ]);

// PO get mail
Route::get('po/getReceivingVoucher/{id}', [ 'uses' => 'PurchaseOrderController@getReceivingVoucher' ]);

Route::get('/', function() { 
	if( Auth::check() ) {
		return Redirect::to('dashboard');
	} else {
		return Redirect::to('login');
	}
// 	return View::make('layout.default.template');
});

/* Cron Jobs Functions - Temporary */
Route::get('sync-order',function() {
	Sync::fromClientToMainOrder();
});

Route::get('top-up/cron', array('uses' => 'TopUpController@sendEmail'));
/* End Cron Jobs Functions*/


/*
 * Geoffrey END Added Authentication Code
 */
Route::group(array('before' => 'auth'), function() { 
	// Extra Routes before resourcing controllers
	include 'routes/misc.php';
	
	// Dashboard
	Route::get('dashboard', array(
		'uses' => 'HomeController@dashboard'
	));
	
	
	// Topup Export
	Route::get('top-up/export', array('uses'=> 'TopUpController@exportOrder'));
	
	// Top Up  - Route
	Route::resource('top-up', 'TopUpController');

	// Processing - Retrieve Items
	Route::post('processing/generatePo/', 'ProcessingController@generatePo');
	Route::resource('processing', 'ProcessingController');
	
	// Sales Order Export
	Route::get('po/export-so/{print?}', array('uses'=> 'PurchaseOrderController@generateSO'));

	// Purchase Order  - Route
	Route::resource('po', 'PurchaseOrderController');
	
	// For Delivery  - Route 
	Route::resource('for-delivery', 'ForDeliveryController');
	
	// User Lists
	Route::resource('user','UserController');
	
	// User Group Lists
	Route::resource('user-group','UserGroupController');
	
	// Order Lists
	Route::resource('order','OrderController');
	
	// Holiday List
	Route::resource( 'holiday','HolidayController' );
});


App::before(function($request){
	$headers = array('Cache-Control'=>'no-cache, no-store, max-age=0, must-revalidate','Pragma'=>'no-cache','Expires'=>'Fri, 01 Jan 1990 00:00:00 GMT');
	View::share('headers', $headers);
});

App::after(function($request, $response){
	$response->headers->set('Cache-Control','nocache, no-store, max-age=0, must-revalidate');
	$response->headers->set('Pragma','no-cache');
	$response->headers->set('Expires','Fri, 01 Jan 1990 00:00:00 GMT');
});
